//
//  CSound.cpp
//  Mario_project
//
//  Created by Vincent Descreux on 19/06/13.
//  Copyright (c) 2013 Vincent Descreux. All rights reserved.
//

#include "CSound.h"

CSound CSound::MixerControl;

CSound::CSound(){
    Mix_Music *Music = NULL;
    Mix_Chunk *Saut = NULL;
    Mix_Chunk *Piece = NULL;
    Mix_Chunk *PowerUp = NULL;
	Mix_Chunk *PowerUpAppears = NULL;
    Mix_Chunk *Yoshi = NULL;
    Mix_Chunk *Pikachu = NULL;
    Mix_Chunk *Life = NULL;
    Mix_Chunk *Death = NULL;
    Mix_Chunk *Start = NULL;
    Mix_Chunk *End = NULL;
    Mix_Chunk *Baby_hit = NULL;
    Mix_Chunk *Big_hit = NULL;
    Mix_Chunk *Checkpoint = NULL;
    Mix_Chunk *Finish = NULL;
	Mix_Chunk *CourseClear = NULL;
	Mix_Chunk *PikaPika = NULL;
}

CSound::~CSound()
{
}

void CSound::PlayMusic(Mix_Music *Music){
    Mix_PlayMusic( Music, -1 );
}
void CSound::PlaySound(Mix_Chunk *Sound){
    Mix_PlayChannel( -1, Sound, 0 );
}

void CSound::StopMusic(){
    Mix_HaltMusic();
}
bool CSound::OnLoad(){
    
    if ( (Music = Mix_LoadMUS( "./sounds/mario_theme.mp3" )) == NULL){
        printf("Mix_LoadMUS(\"music.mp3\"): %s\n", Mix_GetError());
        return false;
    };
    PlayMusic(Music);

    
    if ( (Saut = Mix_LoadWAV("./sounds/jump.wav")) == NULL){
        return false;
    };
    
    if ( (Baby_hit = Mix_LoadWAV("./sounds/babybowser_onhit.wav")) == NULL){
        return false;
    };
    
	if ( (Big_hit = Mix_LoadWAV("./sounds/bowser_onhit.wav")) == NULL){
        return false;
    };

    if ( (Piece = Mix_LoadWAV( "./sounds/piece.wav" )) == NULL){
        return false;
    };

    if ( (PowerUp = Mix_LoadWAV( "./sounds/power-up2.wav" )) == NULL){
        return false;
    };

	    if ( (PowerUpAppears = Mix_LoadWAV( "./sounds/power-up_appears.wav" )) == NULL){
        return false;
    };
    
    if ( (Yoshi = Mix_LoadWAV( "./sounds/yoshi_ow.wav" )) == NULL){
        return false;
    };
    
    if ( (Pikachu = Mix_LoadWAV( "./sounds/pikachu.wav" )) == NULL){
        return false;
    };
	  
	if ( (Checkpoint = Mix_LoadWAV("./sounds/checkpoint.wav")) == NULL){
		return false;
	}
	
	if ( (Finish = Mix_LoadWAV("./sounds/finish.wav")) == NULL){
		return false;
	}

    if ( (CourseClear = Mix_LoadWAV("./sounds/course-clear.wav")) == NULL){
		return false;
	}

	if ( (PikaPika = Mix_LoadWAV("./sounds/pikapika.wav")) == NULL){
		return false;
	}

    Mix_VolumeMusic(80);
    Mix_VolumeChunk(Piece, 5);
    Mix_VolumeChunk(Checkpoint, 100);
    Mix_VolumeChunk(CourseClear, 120);
    Mix_VolumeChunk(Yoshi, 120);
    Mix_VolumeChunk(Pikachu, 50);
    Mix_VolumeChunk(PowerUp, 5);
	Mix_VolumeChunk(PikaPika, 40);
	
	return true;

}




